package com.MIIS.InfoView;

import com.MIIS.R;
import com.MIIS.R.id;
import com.MIIS.R.layout;

import java.util.ArrayList;
import java.util.List;

import android.content.*;
import android.view.*;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class LoadListAdapter extends ArrayAdapter<InfoViewItem>{
	private final int defaultItemPaddingSize = 1;
	private final int subItemPaddingSize = 25;
	
	private List<InfoViewItem> items;
	private Context m_ctx;
	
	public LoadListAdapter(Context context, List<InfoViewItem> items) {
		super(context, 0, items);
		this.items = items;
		m_ctx = context;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		
		if( view == null ) {
			LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.infoview_item, null);
		}
		
		InfoViewItem item = getItem(position);
		
		if( item != null ) {
			TextView tv = (TextView)view.findViewById(R.id.e_infoView_item);
			ImageView iv = (ImageView)view.findViewById(R.id.e_infoView_item_image);
			
			if( item.isSubItem() ) {
				view.setPadding(subItemPaddingSize, defaultItemPaddingSize, defaultItemPaddingSize, defaultItemPaddingSize);
				//set an icon image for your sub items
				iv.setImageResource(R.drawable.icon);
			}else {
				view.setPadding(defaultItemPaddingSize, defaultItemPaddingSize, defaultItemPaddingSize, defaultItemPaddingSize);
				//set an icon image for your main items
				iv.setImageResource(R.drawable.icon);
			}
			
			tv.setText(item.getTitle());
		}
		
		return view;
	}
}
